package org.polyforms.repository.strategy.support;

import org.polyforms.repository.strategy.EntityClassResolvingStrategy;
import org.springframework.core.GenericTypeResolver;

/**
 * Strategy of resolving entity's class for method which declares in classes inherited from generic interface.
 * 
 * @author Kuisong Tong
 * @since 1.0
 */
public class GenericEntityClassResolvingStrategy implements EntityClassResolvingStrategy {
    private final Class<?> genericInterface;

    protected GenericEntityClassResolvingStrategy(final Class<?> genericInterface) {
        this.genericInterface = genericInterface;
    }

    /**
     * {@inheritDoc}
     */
    public final Class<?> getEntityClass(final Class<?> repositoryClass) {
        return GenericTypeResolver.resolveTypeArgument(repositoryClass, genericInterface);
    }
}
